package com.blrs.service.qualification.impl;

import java.util.Date;
import java.util.List;

import com.blrs.common.utils.StringUtils;
import com.blrs.common.utils.uuid.UUID;
import com.blrs.service.qualification.IQualificationResumeService;
import com.blrs.system.domain.SysUploadFile;
import com.blrs.system.mapper.SysUploadFileMapper;
import com.blrs.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.mapper.QualificationResumeMapper;
import com.blrs.domain.QualificationResume;

/**
 * 资质产品履历Service业务层处理
 * 
 * @author yang
 * @date 2023-09-01
 */
@Service
public class QualificationResumeServiceImpl implements IQualificationResumeService
{
    @Autowired
    private QualificationResumeMapper qualificationResumeMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private SysUploadFileMapper sysUploadFileMapper;

    /**
     * 查询资质产品履历
     * 
     * @param id 资质产品履历主键
     * @return 资质产品履历
     */
    @Override
    public QualificationResume selectQualificationResumeById(String id)
    {

        return qualificationResumeMapper.selectQualificationResumeById(id);
    }

    /**
     * 查询资质产品履历列表
     * 
     * @param qualificationResume 资质产品履历
     * @return 资质产品履历
     */
    @Override
    public List<QualificationResume> selectQualificationResumeList(QualificationResume qualificationResume)
    {

        List<QualificationResume> qualificationResumes = qualificationResumeMapper.selectQualificationResumeList(qualificationResume);
        for (QualificationResume resume : qualificationResumes) {
          if (StringUtils.isNotEmpty(resume.getUploadFile())){
              SysUploadFile uploadFile = new SysUploadFile();
              uploadFile.setBusinessId(resume.getUploadFile());
              uploadFile.setBusinessCode("qualification_resume");
              List<SysUploadFile> sysUploadFiles = sysUploadFileMapper.selectSysUploadFileList(uploadFile);
              if (sysUploadFiles.size()>0){
                  resume.setSelectUrl(sysUploadFiles.get(0).getUrl());
               }
          }
        }
        return qualificationResumes;
    }

    /**
     * 新增资质产品履历
     * 
     * @param qualificationResume 资质产品履历
     * @return 结果
     */
    @Override
    public int insertQualificationResume(QualificationResume qualificationResume)
    {
            qualificationResume.setId( UUID.randomUUID().toString().replaceAll("-", ""));
            qualificationResume.setCreateId(sysUserMapper.selectUserByUserName(qualificationResume.getCreateName()).getUserId());
        return qualificationResumeMapper.insertQualificationResume(qualificationResume);
    }

    /**
     * 修改资质产品履历
     * 
     * @param qualificationResume 资质产品履历
     * @return 结果
     */
    @Override
    public int updateQualificationResume(QualificationResume qualificationResume)
    {
        qualificationResume.setOperateTime(new Date());
        return qualificationResumeMapper.updateQualificationResume(qualificationResume);
    }

    /**
     * 批量删除资质产品履历
     * 
     * @param ids 需要删除的资质产品履历主键
     * @return 结果
     */
    @Override
    public int deleteQualificationResumeByIds(Long[] ids)
    {
        return qualificationResumeMapper.deleteQualificationResumeByIds(ids);
    }

    /**
     * 删除资质产品履历信息
     * 
     * @param id 资质产品履历主键
     * @return 结果
     */
    @Override
    public int deleteQualificationResumeById(Long id)
    {
        return qualificationResumeMapper.deleteQualificationResumeById(id);
    }
}
